---
import SingleVerticalListOfPokemonsAutoscrollVue from "@/components/examples/vue/SingleVerticalListOfPokemonsAutoscroll.vue";
import SingleVerticalListOfPokemonsAutoscrollSvelte from "@/components/examples/svelte/SingleVerticalListOfPokemonsAutoscroll.svelte";
import { SingleVerticalListOfPokemonsAutoscroll as SingleVerticalListOfPokemonsAutoscrollReact} from "@/components/examples/react/SingleVerticalListOfPokemonsAutoscroll.tsx";
import PageComponent from "./shared/page-component.astro";
import { getI18N } from "@/i18n";

const { currentLocale } = Astro;
const { framework } = Astro.props;

const i18n = getI18N({ currentLocale });
const vueCode=`
<script setup lang="ts">
import { ref } from "vue";
import { useDragAndDrop } from "fluid-dnd/vue";
import type { Pokemon } from "./Pokemon";
import PokemonComponent from "./PokemonComponent.vue";
import { fetchPokemons } from "@/server/pokemonServer";

const pokemons = ref([] as Pokemon[]);
pokemons.value = await fetchPokemons(9);
const [ parent ] = useDragAndDrop(pokemons,{
  draggingClass: "dragging-pokemon"
});
</script>
<template>
  <div class="flex max-sm:justify-center items-start">
    <div
      ref="parent"
      class="bg-gray-200/60 border-solid border-black/40 rounded-2xl w-60 border-4 p-4 block overflow-auto max-h-[33rem]"
    >
      <PokemonComponent
        v-for="(pokemon, index) in pokemons"
        :key="pokemon.name"
        :index="index"
        :pokemon="pokemon"
      />
    </div>
  </div>
</template>`
const svelteCode = `
<script lang="ts">
import { useDragAndDrop } from "fluid-dnd/svelte";
import type { Pokemon } from "../Pokemon";
import PokemonComponent from "@/components/examples/svelte/PokemonComponent.svelte";
import { fetchPokemons } from "@/server/pokemonServer";

const pokemons = ([] as Pokemon[]);
fetchPokemons(9).then((newPokemons) => {
    pokemons.push(...newPokemons);
});
const [ parent ] = useDragAndDrop(pokemons, {
  draggingClass: "dragging-pokemon",
});
</script>
<div class="flex max-sm:justify-center items-start">
  <div
    use:parent
    class="bg-gray-200/60 border-solid border-black/40 rounded-2xl w-60 border-4 p-4 block overflow-auto max-h-[33rem]"
  >
  {#each pokemons as pokemon, index (pokemon.name)}
    <PokemonComponent
      index={index}
      pokemon={pokemon}
    />
  {/each}
  </div>
</div>
`
const reactCode = `
import { useDragAndDrop } from "fluid-dnd/react";
import type { Pokemon } from "../Pokemon";
import { fetchPokemons } from "@/server/pokemonServer";
import { PokemonComponent } from "./PokemonComponent";
import { useEffect } from "react";

export const SingleVerticalListOfPokemonsAutoscroll: React.FC = () => {
  const [ parent, listOfPokemons, setPokemons ] = useDragAndDrop<Pokemon, HTMLDivElement>([], {
    draggingClass: "dragging-pokemon",
  });
  useEffect(() => { 
      const fetchPokemonse = async () => {
          const newPokemons = await fetchPokemons(9);
          setPokemons(newPokemons);
      }
      fetchPokemonse();
  }, [])

  return (
    <div className="flex max-sm:justify-center items-start">
      <div
        ref={parent}
        className="bg-gray-200/60 border-solid border-black/40 rounded-2xl w-60 border-4 p-4 block overflow-auto max-h-[33rem]"
      >
        {
          listOfPokemons.map((pokemon, index) => (
            <PokemonComponent
              key={pokemon.name}
              index={index}
              pokemon={pokemon}
            />
          ))
        }
      </div>
    </div>
  )
}
`
const fileName = 'SingleVerticalListOfPokemonsAutoscroll';

---


<PageComponent title={i18n.SINGLE_VERTICAL_LIST_AUTOSCROLL} framework={framework} vueCode={vueCode} svelteCode={svelteCode} reactCode={reactCode} fileName={fileName}>
  <fragment slot="vue">
    <SingleVerticalListOfPokemonsAutoscrollVue client:load />
  </fragment>
  <fragment slot="svelte">
    <SingleVerticalListOfPokemonsAutoscrollSvelte client:load />
  </fragment>
  <fragment slot="react">
    <SingleVerticalListOfPokemonsAutoscrollReact client:load />
  </fragment>
</PageComponent>
